package com.geo.smallcredit.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.geo.smallcredit.R;
import com.geo.smallcredit.util.SharedPreferencesUtils;
import com.geo.smallcredit.utils.net.ImageURL;
import com.geo.smallcredit.vo.FinancialBannerVo.FinancialBanner_data;

public class Second_ImageAdapter extends BaseAdapter {

	private Context mContext;
	private LayoutInflater mInflater;
	private List<FinancialBanner_data> list;
//	private static final int[] ids = {R.drawable.senond_main_lunbo};

	public Second_ImageAdapter(Context context,List<FinancialBanner_data> list) {
		this.list=list;
		mContext = context;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() { 
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	viewholder vh;
	@SuppressWarnings("unused")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			vh=new viewholder();
			convertView = mInflater.inflate(R.layout.image_item, null);
			vh.img=(ImageView) convertView.findViewById(R.id.imgView);
			convertView.setTag(vh);
		}
		vh=(viewholder) convertView.getTag();
		String userid=SharedPreferencesUtils.getString(mContext, "userid", null);
		String token=SharedPreferencesUtils.getString(mContext, "token", null);
		String isbank=SharedPreferencesUtils.getString(mContext, "isbank", null);
		String isbinding=SharedPreferencesUtils.getString(mContext, "isbinding", null);
		//=====================================
	if(userid==null||"".equals(userid)&&token==null||"".equals(token)){
		ApplicationInfo appinfo=mContext.getApplicationInfo();
		int id=mContext.getResources().getIdentifier(list.get(position).getImage(), "drawable", appinfo.packageName);
		vh.img.setImageResource(id);
		}else{
			FinalBitmap.create(mContext).display(vh.img, ImageURL.IMG_URL+list.get(position).getImage());	
		}
		return convertView;
	}
	class viewholder{
		ImageView img;
	}
}